<template>
<div>
    <el-form :model="inputForm" ref="inputForm" v-loading="loading"   :disabled="formReadOnly"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="24">
            <el-form-item label="设备名称" prop="repiarEquipmentName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.repiarEquipmentName" placeholder="请填写设备名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="责任人" prop="basicdataDutyPeople.id"
                :rules="[
                  {required: true, message:'请选择责任人', trigger:'blur'}
                 ]">
                <user-select :limit='1' :value="inputForm.basicdataDutyPeople.id" @getValue='(value) => {inputForm.basicdataDutyPeople.id=value}'></user-select>
           </el-form-item>
           </el-col >
        <el-col :span="24">
            <el-form-item label="是否需要检修" prop="repiarOrNot"
                :rules="[
                 ]">
              <el-input v-model="inputForm.repiarOrNot" placeholder="请填写是否需要检修"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="检修时间" prop="repiarCheckTime"
                :rules="[
                 ]">
              <el-input v-model="inputForm.repiarCheckTime" placeholder="请填写检修时间"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
</div>
</template>

<script>
  import UserSelect from '@/components/userSelect'
  export default {
    data () {
      return {
        props: {
          businessId: {
            type: String,
            default: ''
          },
          formReadOnly: {
            type: Boolean,
            default: false
          },
          outPutForm: {
            repiarEquipmentName: '',
            repiarOrNot: '',
            repiarCheckTime: ''
          }
        },
        title: '',
        method: '',
        loading: false,
        inputForm: {
          id: '',
          repiarEquipmentName: this.outPutForm.repiarEquipmentName,
          repiarOrNot: this.outPutForm.repiarOrNot,
          repiarCheckTime: this.outPutForm.repiarCheckTime,
          remarks: ''
        }
      }
    },
    components: {
      UserSelect
    },
    watch: {
      'inputForm.repiarEquipmentName': function (newVal, oldVal) {
        console.log(newVal)
        console.log(oldVal)
        console.log(this.inputForm.repiarEquipmentName)
      },
      'businessId': {
        handler (newVal) {
          if (this.businessId) {
            this.init(this.businessId)
          } else {
            this.$nextTick(() => {
              this.$refs.inputForm.resetFields()
            })
          }
        },
        immediate: true,
        deep: false
      }
    },
    methods: {
      init (id) {
         console.log(this.inputForm.repiarEquipmentName)
        if (id) {
          this.loading = true
          this.inputForm.id = id
          this.$nextTick(() => {
            this.$refs.inputForm.resetFields()
            this.$http({
              url: `/flowform/form/repairTask/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.repairTask)
              this.loading = false
            })
          })
        }
      },
      // 表单提交
      saveForm (callback) {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/flowform/form/repairTask/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              if (data && data.success) {
                callback(data.businessTable, data.businessId)
              }
            })
          }
        })
      }
    }
  }
</script>
